package com.ug_project.spring_dict.DataAccess

import com.ug_project.spring_dict.DataAccess.Migrations.BaseIdTable
import com.ug_project.spring_dict.DataAccess.Migrations.BaseTable
import com.ug_project.spring_dict.Entities.EntityBase
import com.ug_project.spring_dict.Entities.IdEntityBase
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.statements.InsertStatement

fun InsertStatement<*>.fillBasicData(entity: EntityBase) {
    val _table = table as BaseTable
    this[_table.createdAt] = entity.createdAt
    this[_table.updatedAt] = entity.updatedAt
    this[_table.guid] = entity.guid
}

fun ResultRow.getBasicData(table: BaseTable, entity: EntityBase): EntityBase {
    entity.guid = this[table.guid]
    entity.createdAt = this[table.createdAt]
    entity.updatedAt = this[table.updatedAt]

    return entity
}

fun ResultRow.getBasicData(table: BaseIdTable, entity: IdEntityBase): EntityBase {
    getBasicData(table as BaseTable, entity)
    entity.id = this[table.id]
    return entity
}